<template>
  <div class="table-page-search-wrapper">
    <a-card :bordered="false" class="card-area">
      <a-col :md="24" :sm="24">
        <span class="table-page-search-submitButtons">
            <a-button type="primary" @click="()=>this.uploadVisible=true">导入数据</a-button>
        </span>
      </a-col>
    </a-card>
    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        :columns="columns"
        :data="loadData"
        :alert="{ show: true }"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
      >
        <template slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </template>
        <template slot="operation" slot-scope="text, record, index">
          <a-popconfirm title="是否要删除此行？" @confirm="deleteById(record)">
            <a>删除本年度考点数据</a>
          </a-popconfirm>
        </template>
      </s-table>
    </a-card>
    <upload-modal
      ref="uploadModal"
      :uploadVisible.sync="uploadVisible"
      @close="() => { uploadVisible = false }"
      @closeUpload="() => { uploadVisible = false }"
    />
  </div>

</template>

<script>
  import {STable} from '~'
  import {mapState} from 'vuex'
  import uploadModal from "./uploadModal";


  export default {
    name: 'examPlanPage',
    data() {
      return {
        advanced: true,
        columns: [
          {
            title: '序号',
            scopedSlots: {customRender: 'serial'}
          },
          {
            title: '用户编号',
            dataIndex: 'loginCode'
          },
          {
            title: '用户名',
            dataIndex: 'nickname'
          },
          {
            title: '更新时间',
            dataIndex: 'updateTime'
          },
          {
            title: '数据总量',
            dataIndex: 'size'
          },
          {
            title: '招生年度',
            dataIndex: 'zsnd'
          },
          {
            title: '操作',
            width: '160px',
            dataIndex: 'operation',
            fixed: 'right',
            scopedSlots: {customRender: 'operation'}
          }
        ],
        parameter: {
          pageNo: 1,
          pageSize: 10
        },
        loadData: parameter => {
          this.parameter = parameter
          parameter.pageNum = parameter.pageNo
          let params = Object.assign({}, parameter)
          return this.$api.examPlan.page(params).then(res => {
            return {
              data: res.data.rows,
              pageNo: parameter.pageNum,
              pageSize: parameter.pageSize,
              totalPage: Math.ceil(res.data.total / parameter.pageSize),
              totalCount: res.data.total

            }
          })
        },
        selectMenu: {
          yx: []
        },
        uploadVisible: false,
        detailVisible: false,
        confirmLoading: false,
        confirmAdLoading: false,
        courseInfo: {},
        kcLoading: false,
        initDone: false,
        uploadUrl: `${process.env.SERVICE_URL}admissions/kdap/upload`
      }
    },
    components: {uploadModal, STable},
    computed: {},
    created() {
    },
    methods: {
      deleteById(record) {

        this.$api.examPlan.delete(record.id).then(res => {
          this.$message.success(res.msg)
          this.$refs.table.refresh(true)
        })
      },
      handleChange(info) {
        console.log(info)
        if (info.file.response.status === 1) {
          this.$message.success('导入成功');
          this.$refs.table.refresh(false)
        } else if (info.file.response.status === 0) {
          this.$message.error(info.file.response.msg || '导入失败');
        }
      },
    }
  }
</script>
